import { request } from '../request';

export function getRouteList(params: Pick<Api.Common.PaginatingCommonParams, 'current' | 'size'>) {
  return request<Api.Common.PaginatingQueryRecord<Api.System.Route>>({
    url: '/role/get-all-roles',
    params
  });
}

export function getRoute(params: { id: number }) {
  return request<Api.System.Route>({
    url: `/role/${params.id}`
  });
}

// 获取所有权限
export function getAllPermission() {
  return request<Api.System.Permission[]>({
    url: '/permission/get-all-prmission'
  });
}

// 更新角色信息
export function updateRoute(
  params: Partial<Omit<Api.System.Route, 'id' | 'permissions'>> & { id: number; permissionIds?: number[] }
) {
  return request<string>({
    url: `/role/${params.id}`,
    method: 'patch',
    data: params
  });
}

// 删除角色
export function deleteRoute(params: { id: number }) {
  return request<Api.System.Route>({
    url: `/role/${params.id}`,
    method: 'delete'
  });
}

// 创建角色
export function createRoute(params: Partial<Omit<Api.System.RouteCreate, 'id'>>) {
  return request<string>({
    url: '/role',
    method: 'post',
    data: params
  });
}

// 获取用户列表
export function getUserList(params: Pick<Api.Common.PaginatingCommonParams, 'current' | 'size'>) {
  return request<Api.Common.PaginatingQueryRecord<Api.System.User>>({
    url: '/user/get-all-users',
    params
  });
}

// 新增用户
export function createUser(params: Api.System.CreateUser) {
  return request<Api.System.User>({
    url: '/user',
    method: 'post',
    data: params
  });
}

// 更新用户
export function updateUser(params: Api.System.UpdateUser) {
  const { id, ...rest } = params;
  return request<Api.System.User>({
    url: `/user/${id}`,
    method: 'patch',
    data: rest
  });
}

// 删除用户
export function deleteUser(params: { id: number }) {
  return request<Api.System.User>({
    url: `/user/${params.id}`,
    method: 'delete'
  });
}
// 查看日志
export function findAll(params: Pick<Api.Common.PaginatingCommonParams, 'current' | 'size'>) {
  return request<Api.Common.PaginatingQueryRecord<Api.System.Log>>({
    url: `/log`,
    params
  });
}
